package com.hongpu.controller;


import com.hongpu.domain.HpProjectWorkPayListDetail;
import com.hongpu.enums.InvoiceTypeEnum;
import com.hongpu.enums.ItHasBeenInvoicedEnum;
import com.hongpu.enums.YesOrNoEnum;
import com.hongpu.service.HpProjectWorkPayListDetailService;
import com.hongpu.utils.ResultDto;
import com.hongpu.vo.InvoiceTypeVo;
import com.hongpu.vo.ItHasBeenInvoicedVo;
import com.hongpu.vo.YesOrNoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 张玉胜
 * @since 2025年05月08日
 */
@RestController
@RequestMapping("/hpProjectWorkPayListDetail")
public class HpProjectWorkPayListDetailController {

    @Autowired
    HpProjectWorkPayListDetailService hpProjectWorkPayListDetailService;

    /**
     * 是否开票
     * @return
     */
    @GetMapping(value = "/invoiceOrNot")
    public ResultDto invoiceOrNot(){
        YesOrNoEnum[] values = YesOrNoEnum.values();
        List<YesOrNoVo> list = new ArrayList<>();
        for (YesOrNoEnum yesOrNoEnum : values) {
            YesOrNoVo yesOrNoVo = new YesOrNoVo();
            yesOrNoVo.setValue(yesOrNoEnum.getValue());
            yesOrNoVo.setDesc(yesOrNoEnum.getDesc());
            list.add(yesOrNoVo);
        }
        return ResultDto.ok(list);
    }

    /**
     * 发票类型
     * @return
     */
    @GetMapping(value = "/invoiceType")
    public ResultDto invoiceType(){
        InvoiceTypeEnum[] values = InvoiceTypeEnum.values();
        List<InvoiceTypeVo> list = new ArrayList<>();
        for (InvoiceTypeEnum invoiceTypeEnum : values) {
            InvoiceTypeVo invoiceTypeVo = new InvoiceTypeVo();
            invoiceTypeVo.setValue(invoiceTypeEnum.getValue());
            invoiceTypeVo.setDesc(invoiceTypeEnum.getDescription());
            list.add(invoiceTypeVo);
        }
        return ResultDto.ok(list);
    }

    /**
     * 发票状态
     * @return
     */
    @GetMapping(value = "/itHasBeenInvoiced")
    public ResultDto itHasBeenInvoiced(){
        ItHasBeenInvoicedEnum[] values = ItHasBeenInvoicedEnum.values();
        List<ItHasBeenInvoicedVo> list = new ArrayList<>();
        for (ItHasBeenInvoicedEnum itHasBeenInvoicedEnum : values) {
            ItHasBeenInvoicedVo itHasBeenInvoicedVo = new ItHasBeenInvoicedVo();
            itHasBeenInvoicedVo.setValue(itHasBeenInvoicedEnum.getValue());
            itHasBeenInvoicedVo.setDesc(itHasBeenInvoicedEnum.getDesc());
            list.add(itHasBeenInvoicedVo);
        }
        return ResultDto.ok(list);
    }




    /**
     * 新增
     */
    @PostMapping(value = "/add")
    public ResultDto add(@RequestBody HpProjectWorkPayListDetail hpProjectWorkPayListDetail){
        boolean add = hpProjectWorkPayListDetailService.add(hpProjectWorkPayListDetail);
        if(add){
            return ResultDto.ok();
        }else {
            return ResultDto.fail();
        }
    }
    /**
     * 删除
     */
    @GetMapping(value = "/delete/{id}")
    public ResultDto delete(@PathVariable("id") Long id){
        boolean add = hpProjectWorkPayListDetailService.delete(id);
        if(add){
            return ResultDto.ok();
        }else {
            return ResultDto.fail();
        }
    }
    /**
     * 修改
     */
    @PostMapping(value = "/update")
    public ResultDto update(@RequestBody HpProjectWorkPayListDetail hpProjectWorkPayListDetail){
        return hpProjectWorkPayListDetailService.update(hpProjectWorkPayListDetail);
    }

}